
local MainScene = class("MainScene", cc.load("mvc").ViewBase)

function MainScene:onCreate()
    -- add background image
    local sprite = display.newSprite("HelloWorld.png")
        :move(display.center)
        :addTo(self)


    -- 添加触摸事件监听器
    local function onTouchBegan(touch, event)
        local location = touch:getLocation()
        local spriteRect = sprite:getBoundingBox()
        if cc.rectContainsPoint(spriteRect, location) then
            -- 跳转到HelloWorldScene
            local MenuScene = require("app.views.MenuScene")
            local scene = MenuScene:create()
            cc.Director:getInstance():replaceScene(scene)
            return true
        end
        return false
    end



    local listener = cc.EventListenerTouchOneByOne:create()
    listener:setSwallowTouches(true)
    listener:registerScriptHandler(onTouchBegan, cc.Handler.EVENT_TOUCH_BEGAN)
    local eventDispatcher = self:getEventDispatcher()
    eventDispatcher:addEventListenerWithSceneGraphPriority(listener, sprite)

    -- add HelloWorld label
    cc.Label:createWithSystemFont("Hello World1", "Arial", 40)
        :move(display.cx, display.cy + 200)
        :addTo(self)

end

return MainScene
